package com.cyx.spring.jdbc.rowmapper;

import java.util.HashMap;
import java.util.Map;

/**
 * RowMapperFactory
 *
 * @author yongxiang
 * @date 2024/10/25 9:43
 * @desc
 */
public class RowMapperFactory {

    private static Map<Class<?>,RowMapper<?>> mapperFactory = new HashMap<>();

    static {
        mapperFactory.put(String.class,new StringMapper());
        mapperFactory.put(Boolean.class,new StringMapper());
        mapperFactory.put(Number.class,new StringMapper());
    }

    public static<T>  RowMapper<T> getRowMapper(Class<T> clazz){
        RowMapper<T> rowMapper = (RowMapper<T>) mapperFactory.get(clazz);
        if(rowMapper == null){
            rowMapper = new BeanMapper<>(clazz);
            mapperFactory.put(clazz,rowMapper);
        }
        return rowMapper;
    }
}
